<template>
    <div class="goods-list-item" @click="itemClick">
      <img :src="showGoods" alt="" @load="imgLoad"/>
      <div class="goods-info">
        <p>{{goodsItem.title}}</p>
        <span class="price">{{goodsItem.price}}</span>
        <span class="collect">{{goodsItem.cfav}}</span>
      </div>
    </div>
</template>

<script>
export default {
  name: "GoodsLIstItem",
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    showGoods() {
      return this.goodsItem.image || this.goodsItem.show.img
    }
  },
  methods: {
    imgLoad() {
      this.$bus.$emit('itemImgLoad')
    },
    itemClick() {
      this.$router.push('/detail/' + this.goodsItem.iid)
    }
  }
}
</script>

<style scoped>
  .goods-list-item {
    width: 48%;
  }
  .goods-list-item img {
    width: 100%;
    border-radius: 5px;
  }
  .goods-info {
    text-align: center;
    font-size: 12px;
    margin: 5px 0;
  }
  .goods-info p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }
  .price {
    position: relative;
    color: var(--color-high-text);
    margin-right: 20px;
  }
  .price::after {
    content: '';
    position: absolute;
    left: 34px;
    top: 1px;
    width: 14px;
    height: 14px;
    background: url("~assets/common/collect.jpg") 0 0/14px 14px;
  }
</style>
